import request from "./request/index.js";

export async function addPurchaseOrder(data) {
  try {
    const res = await request.post("/purchase-order", data);
    return res.data;
  } catch (err) {
    return Promise.reject(err);
  }
}

export async function listPurchaseOrders(data) {
  try {
    const res = await request.post("/purchase-order/list", data);
    return res.data;
  } catch (err) {
    return Promise.reject(err);
  }
}

export async function getPurchaseOrder(id) {
  try {
    const res = await request.get(`/purchase-order/${id}`);
    return res.data;
  } catch (err) {
    return Promise.reject(err);
  }
}

export async function updatePurchaseOrder(data) {
  try {
    const res = await request.put('/purchase-order', data);
    return res.data;
  } catch (err) {
    return Promise.reject(err);
  }
}

export async function redPurchaseOrder(id) {
  try {
    const res = await request.post(`/purchase-order/red/${id}`);
    return res.data;
  } catch (err) {
    return Promise.reject(err);
  }
}
